#include<iostream>
#include<cmath>

#define LL long long

using namespace std;

const int maxn=65535;

struct hash
{
	LL a,b,next;
}Hash[maxn*2];

LL flg[maxn+66];
LL top,idx;

void ins(LL a,LL b)
{
	LL k=b & maxn;
	if(flg[k] != idx)
	{
		flg[k]=idx;
		Hash[k].next=-1;
		Hash[k].a=a;
		Hash[k].b=b;
		return;
	}
	while(Hash[k].next != -1)
	{
		if(Hash[k].b == b)return;
		k=Hash[k].next;
	}
	Hash[k].next= ++top;
	Hash[top].next = -1;
	Hash[top].a = a;
	Hash[top].b = b;
}

LL find(int b)
{
	int k= b & maxn;
	if(flg[k] != idx )return -1;
	while(k != -1)
	{
		if(Hash[k].b == b)
			return Hash[k].a;
		k=Hash[k].next;
	}
	return -1;
}

LL gcd(LL a,LL b)
{
	return b==0?a:gcd(b,a%b);
}

LL exgcd(LL a,LL b, LL &x, LL &y)
{
	LL t,ret;
	if(!b){x=1;y=0;return a;}
	ret=exgcd(b,a%b,x,y);
	t=x;x=y;y=t-a/b*y;
	return ret;
}

LL Inval(LL a,LL b,LL n)
{
	LL x,y,e;
	exgcd(a,n,x,y);
	e=x*b%n;
	return e<0?e+n:e;
}

LL pow_mod(LL a,LL b,LL c)
{
	LL ret=1%c;a%=c;
	while(b)
	{
		if(b&1)
			ret=ret*a%c;
		a=a*a%c;
		b>>=1;
	}
	return ret;
}

LL BabyStep(LL A,LL B,LL C)
{
	top=maxn;++idx;
	LL buf=1%C,D=buf,K;
	LL d=0,tmp;
	for(int i=0;i<=100;buf=buf*A%C,++i)
		if(buf == B)
			return i;
	while((tmp=gcd(A,C)) != 1)
	{
		if(B%tmp)return -1;
		++d;
		C/=tmp;
		B/=tmp;
		D=D*A/tmp%C;
	}
	LL M=(LL)ceil(sqrt((double)C));
	for(int i=0,buf=1%C;i<=M;buf=buf*A%C,i++)ins(i,buf);
	for(int i=0,K=pow_mod(A,M,C);i<=M;D=D*K%C,i++)
	{
		tmp=Inval(D,B,C);LL w;
		if(tmp>=0&&(w=find(tmp))!=-1)
			return i*M+w+d;
	}
	return -1;
}

int main()
{
	LL A,B,C;
	while(cin>>A>>C>>B)
	{
		if(A==0&&B==0&&C==0)break;
		B%=C;LL tmp=BabyStep(A,B,C);
		if(tmp <0 )
			cout<<"No Solution"<<endl;
		else
			cout<<tmp<<endl;
	}
	return 0;
}
